#ifndef YEP_UI_TEXT_INPUT
#define YEP_UI_TEXT_INPUT

#include <string>
#include <climits>
#include "Widget.hpp"

namespace yep
{
    /**
     * @brief A simple input
     **/
    class TextInput: public Widget
    {
    public:
        /**
         * @brief Constructor
         **/
        TextInput()
        {
            maxLength(0);
        }

        /**
         * @brief Draws the text input
         **/
        void onDraw(SDL_Surface *screen)
        {
            style->drawTextInput(screen, _text, isFocused(), getAbsolutePosition(), getAbsoluteArea(), getTextColor(), getBackgroundColor()  );
        }

//        /**
//         * @brief On event
//         **/
//        bool onEvent(SDL_Event &event)
//        {
//            if(focused() && event.type == SDL_KEYDOWN)
//            {
//                Uint16 unicode = event.key.keysym.unicode;
//                SDLKey sym = event.key.keysym.sym;
//                if(unicode >= ' ')
//                {
//                    if(_text.size() < _maxLength)
//                        _text += unicode;
//                    else
//                        _text[_text.size()-1] = unicode;
//                    return true;
//                }
//                else if(sym == SDLK_BACKSPACE)
//                {
//                    _text.erase(_text.size()-1,1);
//                    return true;
//                }
//            }
//            return Widget::onEvent(event);
//        }

        /**
         * @brief Return the text
         **/
        string text() const
        {
            return _text;
        }

        /**
         * @brief Changes the text
         **/
        void text(const string &value)
        {
            _text = value;
        }

        /**
         * @brief Returns the maximum length of characters.
         **/
        unsigned maxLength() const
        {
            return _maxLength;
        }

        /**
         * @brief Changes the maximum length of characers.
         *
         * @param value The new max. If zero is passed, it is replaced for INT_MAX.
         **/
        void maxLength(unsigned value)
        {
            if(value)
                _maxLength = value;
            else
                _maxLength = INT_MAX;
        }

    private:
        string _text;
        unsigned _maxLength;
    };
}

#endif // YEP_UI_TEXT_INPUT

